#ifndef ABSTRACTPAGEPARSER_H
#define ABSTRACTPAGEPARSER_H

#include <QObject>
#include <QUrl>

#include <gumbo.h>

class QNetworkAccessManager;
class QNetworkReply;
namespace Jcr
{

class AbstractPageParserPrivate;
class AbstractPageParser : public QObject
{
    Q_OBJECT
public:
    explicit AbstractPageParser(QObject *parent = 0);
    virtual ~AbstractPageParser();

    void setUrl(const QUrl& url);
    QUrl url() const;

    void setFile(const QString& file);
    QString file() const;

    void setWriteFile(const QString& writeFile);
    QString writeFile() const;

public slots:
    virtual void run();

signals:
    void finished();

protected slots:
    virtual void onReply(QNetworkReply* reply);

protected:
    QNetworkAccessManager* networkMgr() const;
    virtual void parsePage(const QByteArray& data);
    virtual void processNode(GumboNode* node) = 0;
    virtual void finalize() {}
    GumboOutput* output() const;
    void traverseNode(GumboNode* root);

private:
    Q_DISABLE_COPY(AbstractPageParser)
    AbstractPageParserPrivate* d_ptr;
};

} // namespace jcr
#endif // ABSTRACTPAGEPARSER_H
